<?php
//企业相册
if(!defined('IN_T')){
   die('hacking attempt');
}

//编辑相册
if($act == "detail"){

	$tid = intval($_REQUEST['tid']);
	$thumb = $Db->query("SELECT * FROM ".$Base->table('company_thumb')." WHERE id=$tid AND c_id = ".$GLOBALS['company']['c_id']."","Row");
	//判断是否非法访问
	if(empty($thumb)){
		$tid = 0;
	}
	//前台显示
	if(empty($_POST)){
		$tp->assign('thumb',$thumb);
	}
	//数据处理
	else{
		$res['status'] = 0;

		$data = array(
			'id'=>$tid,
			'c_id'=>$company['c_id'],
			'img_name'=>Common::sfilter($_POST['img_name']),
			'img_path'=>Common::sfilter($_POST['thumb_path']),
			'sort'=>intval($_POST['sort'])
			);
		// var_dump($data);die;
		if(empty($data['img_name'])){
			$res['msg'] = '图片名不能为空！';
		}
		else if(empty($data['img_path'])){
			$res['msg'] = '图片不能为空！';
		}
		else if(empty($data['sort'])){
			$res['msg'] = '排序不能为空！';
		}
		else{
			$Db->replace($Base->table('company_thumb'),$data);
			$res = array('status'=>'1','msg'=>'提交成功','href'=>'/'.COMPANY_PATH.'/?m=thumb');
		}
		echo $Json->encode($res);
		exit;
	}
}
//删除相册
else if($act == 'delete'){

	$id = intval($_POST['tid']);
	$res['status'] = 0;
	//验证是否是非法操作
	$Db->execSql("delete from ".$Base->table('company_thumb')." where id=$id and c_id = ".$GLOBALS['company']['c_id']."");
	echo $Json->encode(array('status'=>1,'msg'=>'删除成功'));
	exit;

}
//列表显示
else if($act == 'index'){
	$tp->assign('thumb',thumbList());
}

$tp->assign('act',$act);
$tp->assign('nav','企业相册');

function thumbList(){
	$sql = "SELECT * FROM ".$GLOBALS['Base']->table('company_thumb')." WHERE c_id = ".$GLOBALS['company']['c_id']." ";
	
	$sql .= " ORDER BY sort ";
	// echo $sql;
	$list = $GLOBALS['Db']->query($sql);
	return $list;
}
?>